<?php
class PersonaBusqueda
{
	static function getFormulario($form, $collectionPersons, $maxPerson = 1)
	{	
		$persona = new Persona();
		
		$options = array(	
							'beforeSend' => "function(){ return persona.beforeSearch('" . CHtml::activeId($persona, 'persona_tipodocumento_id') . "','" 
																		. CHtml::activeId($persona, 'persona_numerodocumento') . "','"
																		. $maxPerson . "','"
																		. "tbodyPerson" . "','"
																		. Yii::t('core_labels', 'Loading...') . 
																		"');}",
							'type'=>'POST', //request type
							'success' => "js:function(data){ persona.successSearch(
																						data, 
																						'" . CHtml::activeId($persona, 'person_tipodocumento_id') . "','" 
																						. CHtml::activeId($persona, 'persona_numerodocumento') . "','"
																						. "tbodyPerson" . "','"
																						. Yii::t('core_labels', 'Borrar') . "','"
																						. Yii::t('person_labels', 'Esta Seguro de eliminar: ') . 
																					"');
															}",
															
							//'data'=>'js:javascript statement' 
															//leave out the data key to pass all form values through
		);?>
		<div class="grid_8">
			<?php 
			echo $form->labelEx($persona,'persona_numerodocumento');
			echo $form->dropDownList(
	        							$persona,
	        							'persona_tipodocumento_id',
	                                    CHtml::listData(
	                                    					TipoDocumento::model()->findAll(),
	                                    					'tipodocumento_id',
															'tipodocumento_abreviacion'
														),
										array('class'=>'width_half','style'=>'width:20%;')
										); 
			echo $form->textField($persona,'persona_numerodocumento',array('maxlength'=>20,'class'=>'width_half','style'=>'width:40%;'));
			echo CHtml::ajaxButton(
									Yii::t('core_labels', 'Search'),
									Yii::app()->getRequest()->getBaseUrl() . '/persona/Persona/Search',
									$options
								);							
			echo $form->error($persona,'person_tipodocumento_id');
			echo $form->error($persona,'persona_numerodocumento');  
			?>
		</div>
		<div class="grid_8" id="personResultSearchMessage"></div>
		<div id="divPerson" class="grid_8">
			<table id="tblPerson">
				<thead>
					<tr>
						<th><?php echo Yii::t('person_labels', t('Apellido','persona_etiqueta'))?></th>
						<th><?php echo Yii::t('person_labels', t('Nombre','persona_etiqueta'))?></th>
						<th><?php echo Yii::t('person_labels', t('Tipo DOC','persona_etiqueta'))?></th>
						<th><?php echo Yii::t('person_labels', t('Documento','persona_etiqueta'))?></th>
						<th><?php echo Yii::t('person_labels', t('F. Nacimiento','persona_etiqueta'))?></th>
						<th><?php echo Yii::t('core_labels', 'Action')?></th>
					</tr>
				</thead>
				<tbody id="tbodyPerson">
				<?php
					if(is_array($collectionPersons))
					{
				
						foreach ($collectionPersons as $tmpPerson)
						{
							$trId = 'tbodyPerson_tr_' . $tmpPerson->persona_tipodocumento_id .'_'.$tmpPerson->persona_numerodocumento;
							$confirmMessage = Yii::t('person_labels', 'Are you sure to delete:') . $tmpPerson->persona_apellido . ', ' . $tmpPerson->persona_nombres;
							$clickAction = "persona.deleteSelectedPerson('" . $trId .  "','" . $confirmMessage . "')";
						?>
						<tr id="<?php echo $trId;?>">
							<td><?php echo $tmpPerson->persona_apellido;?></td>
							<td><?php echo $tmpPerson->persona_nombres; ?></td>
							<td><?php echo $tmpPerson->tipoDocumento->tipodocumento_abreviacion; ?></td>
							<td><?php echo $tmpPerson->persona_numerodocumento; ?></td>
							<td><?php echo $tmpPerson->persona_fechanacimiento; ?></td>
							<td>
								<input type="button" onClick="<?php echo $clickAction; ?>" value="<?php echo Yii::t('core_labels', 'Delete');?>"  />
								<input type="hidden" name="Persona[temporal_tipodocumento_id][]" value="<?php echo $tmpPerson->persona_tipodocumento_id;?>" />
								<input type="hidden" name="Persona[temporal_numerodocumento][]" value="<?php echo $tmpPerson->persona_numerodocumento;?>" />
							</td>
						</tr>
						<?php 
						}
					}
					?>
				</tbody>
			</table>
		</div>
	<?php 
	}
}	



															